// 首屏展示
let bannerShow = function(){
    $.ajax({
        type:'get',
        url:'/admin/showStoreBanner',
        data:'',
        success:function(data){
            let showTop = template('banner_top_temp', {
                list: data
            })
            $('#banner_top_img').html(showTop)
        }
    })
}
bannerShow()

// 上传图片
$('#banner_top_img').on('change','.upfile',function(){
    let file = $(this)[0].files[0];
    // 3.实例化formdata
    let formdata = new FormData();
    // 4.把input的文件信息添加到formdata
    formdata.append('avatar', file);
    // console.log(formdata);
    let ids = $(this).data('id')
    $.ajax({
        type:'post',
        url:'/admin/upBannerStore',
        data:formdata,
        contentType: false,
        processData: false,
        success:function(data){
           if(data.code == 21101){
            $.ajax({
                type:'post',
                url:'/admin/pushBannerStore',
                data:{keys:ids,mas:data.pic},
                success:function(datas){
                    if(datas.code == 21102){
                        bannerShow()
                        alert('修改成功')
                    }else{
                        alert('修改失败')
                    }
                }
            })
           }else{
               alert('修改失败')
           }
            
        }
    })
})